﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Test_WebDriver.Utilities;
using OpenQA.Selenium;

namespace Test_WebDriver
{
	/// <summary>
	///		<para>Summary: Web Automation on Other Browsers: FireFox, Chrome, Opera, IE</para>
	///		<para>Author: Heller (Hellersong@outlook.com)</para>
	///		<para>Creation: 7/11/2015 10:22:41 AM</para>
	/// </summary>
	[TestClass]
	public class TestMultiBrowser
	{
		[TestMethod]
		public void test_demo_ie()
		{
			try
			{
				WebUtility.CreateDriver(BrowserType.IE);
				WebUtility.OpenUrl("https://www.baidu.com/");
				IWebElement txtBox = WebUtility.GetElementById("kw");
				txtBox.Click();
				WebUtility.SetValue("Ss", txtBox);
				WebUtility.Actions.SendKeys(Keys.Escape).Perform();
				WebUtility.PauseSecond(1);
				IWebElement searchBtn = WebUtility.GetElementById("su");
				searchBtn.Click();
				WebUtility.PauseSecond(5);
			}
			catch (Exception)
			{
				throw;
			}
			finally
			{
				WebUtility.DestroyDriver();
			}
		}

		[TestMethod]
		public void test_demo_chrome()
		{
			try
			{
				WebUtility.CreateDriver(BrowserType.CHROME);
				WebUtility.OpenUrl("https://www.baidu.com/");
				IWebElement txtBox = WebUtility.GetElementById("kw");
				txtBox.Click();
				WebUtility.SetValue("Ss", txtBox);
				WebUtility.Actions.SendKeys(Keys.Escape).Perform();
				WebUtility.PauseSecond(1);
				IWebElement searchBtn = WebUtility.GetElementById("su");
				searchBtn.Click();
				WebUtility.PauseSecond(5);
			}
			catch (Exception)
			{
				throw;
			}
			finally
			{
				WebUtility.DestroyDriver();
			}
		}

		[TestMethod]
		public void test_demo_firefox()
		{
			try
			{
				WebUtility.CreateDriver(BrowserType.FIREFOX);
				WebUtility.OpenUrl("https://www.baidu.com/");
				IWebElement txtBox = WebUtility.GetElementById("kw");
				txtBox.Click();
				WebUtility.SetValue("Ss", txtBox);
				WebUtility.Actions.SendKeys(Keys.Escape).Perform();
				WebUtility.PauseSecond(1);
				IWebElement searchBtn = WebUtility.GetElementById("su");
				searchBtn.Click();
				WebUtility.PauseSecond(5);
			}
			catch (Exception)
			{
				throw;
			}
			finally
			{
				WebUtility.DestroyDriver();
			}
		}
	}
}
